import homeStore from "../../../store/home_store"
import {
  throttle
} from 'underscore'


Page({

  /**
   * 页面的初始数据
   */
  data: {
    addressInfo: '',
    lists: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    const {
      id
    } = options
    homeStore.dispatch('fetchDetailsAction', id)
    homeStore.onState('details', this.handleDetailsValue)
  },

  // 数据赋值
  handleDetailsValue(value) {
    let arr = []
    arr.push(value)
    this.setData({
      lists: arr
    })
  },

  // 页面卸载
  onUnload() {
    homeStore.offState('details', this.handleDetailsValue)
  },

  // 获取收货地址
  async handleAddress() {
    const addressInfo = await wx.chooseAddress()
    this.setData({
      addressInfo
    })
  },

  // 提交按钮
  handleSubmit: throttle(function() {
    if (this.data.addressInfo) {
      wx.showToast({
        title: '提交成功',
      })
    } else {
      wx.showToast({
        icon: 'error',
        title: '没有选择收货地址',
      })
    }
  }, 500)
})